package com.muk.meis.model.service;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityTransaction;

import org.apache.catalina.ant.FindLeaksTask;

import com.muk.meis.model.bean.SchoolNew;

public class SchoolNewsService extends BaseMEISService {

	public List<SchoolNew> listAll(){
		List<SchoolNew> lst = em.createQuery("select e from SchoolNew e ",SchoolNew.class).getResultList();
		return lst;
	}
	
	public List<SchoolNew> listByPerCode(String perCode){
		List<SchoolNew> lst = em.createQuery("select e from SchoolNew e where e.percodeCode = '"+perCode+"' order by e.createDate desc",SchoolNew.class).getResultList();
		return lst;
	}	
	
	public SchoolNew getDetail(Integer newsId){
		 return em.find(SchoolNew.class, newsId);
	}
	
	public void create(SchoolNew schoolNews){
		EntityTransaction t = em.getTransaction();
		t.begin();
		em.persist(schoolNews);
		t.commit();
	}
	
	public void update(SchoolNew schoolNews){
		EntityTransaction t = em.getTransaction();
		t.begin();
	    SchoolNew newObj = em.find(SchoolNew.class, schoolNews.getNewsId());
	    newObj.setTitle(schoolNews.getTitle());
	    newObj.setMessage(schoolNews.getMessage());
	    newObj.setCreateDate(schoolNews.getCreateDate());
	    em.persist(newObj);
	    t.commit();
	}
	
	public static void main(String[] args) {
		SchoolNewsService service = new SchoolNewsService();
		System.out.println(service.listByPerCode("730063").get(0).getUserId());
	}
	
}
